package com.dd.dus.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.dc.entity.users.DPermission;
import com.dd.dus.service.impl.DPermissionServiceImpl;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 权限/菜单信息表 前端控制器
 * </p>
 *
 * @author JueDream
 * @since 2021-03-05
 */
@Slf4j
@RestController
@RequestMapping("/user/d-permission")
public class DPermissionController {

    @Autowired
    DPermissionServiceImpl permissionService;

    @ApiOperation(value = "菜单列表查询接口")
    @PostMapping(value = "/findPermissionByUserId")
    public List<DPermission> findPermissionByUserId(@RequestParam Integer userId){
        // 根据用户编号查询角色信息
        log.info("UserServcie findPermissionByUserId start ... {}", userId);
        return permissionService.findPermissionByUserId(userId);
    }

    @ApiOperation(value = "根据角色查询菜单接口")
    @PostMapping(value = "/findPermissionByRoleId")
    public List<DPermission> findPermissionByRoleId(@RequestBody List<Integer> roleIds){
        // 根据用户编号查询角色信息
        log.info("UserServcie findPermissionByRoleId start ... {}", roleIds);
        return permissionService.findPermissionByRoleId(roleIds);
    }

    @ApiOperation(value = "权限分页列表查询接口")
    @PostMapping("/queryPermissionList")
    public Page<DPermission> queryPermissionList(@RequestParam int page, @RequestParam int limit, @RequestParam String permissionName){
        log.info("UserServcie queryPermissionList start ... {}");
        return permissionService.queryRoleList(page, limit, permissionName);
    }

    @ApiOperation(value = "角色新增接口")
    @PostMapping("/insert")
    public Integer insert(@RequestBody DPermission permission){
        log.info("UserServcie insert start ... {}", permission);
        return permissionService.insert(permission);
    }

    @ApiOperation(value = "角色更新接口")
    @PostMapping("/updateById")
    public boolean updateById(@RequestBody DPermission permission){
        log.info("UserServcie updateById start ... {}", permission);
        return permissionService.updateById(permission);
    }

    @ApiOperation(value = "角色删除接口")
    @DeleteMapping("/delete")
    public boolean delete(@RequestParam Integer pId){
        return permissionService.removeById(pId);
    }


}
